package mil.af.amc.adpetracker.service;

import mil.af.amc.adpetracker.exceptions.IllegalUnassignmentOfPrimaryCustodianException;
import mil.af.amc.adpetracker.exceptions.UserNotFoundException;
import mil.af.amc.adpetracker.model.AdpeAccount;
import mil.af.amc.adpetracker.model.EquipmentItem;
import mil.af.amc.adpetracker.model.User;
import mil.af.amc.adpetracker.model.DRA;
import mil.af.amc.adpetracker.service.exceptions.AdpeAccountNotFoundException;
import mil.af.amc.adpetracker.service.exceptions.DraNotFoundException;

import java.util.List;
import java.util.Map;

/**
 * Interface for AdpeAccountService implementations
 *
 * @author TSgt Jason Ferguson
 */

public interface AdpeAccountService {

    /**
     * Retrieve an AdpeAccount object by it's unique id
     *
     * @param accountId
     * @return
     */
    public AdpeAccount getById(int accountId);

    public List<AdpeAccount> getAll();

    public List<EquipmentItem> getEquipmentItemList();

    public List<EquipmentItem> getPartialEquipmentItemList(int startPage, int total);

    public List<User> getCustodians();

    /**
     * Retrieve the total value of the EquipmentItems assigned to the ADPE Account
     * @param adpeAccountId     unique id of account to return value for
     * @return  a double representing the account value
     */
    double getAccountValue(int adpeAccountId);
    
    public int getEquipmentItemCount();

    /**
     * Return the count of equipment items assigned to an account
     *
     * @param adpeAccountId     unique id of the adpe account
     * @return
     */
    int getEquipmentItemCount(int adpeAccountId);

    /**
     * Delete an AdpeAccount based on its unique id
     *
     * @param adpeAccountId     int representing the unique id of the AdpeAccount
     * @throws ServiceException
     */
    void deleteAccount(int adpeAccountId) throws ServiceException;
    
    AdpeAccount createAccount(Map acctMap) throws DraNotFoundException;

    public AdpeAccount createAccount(DRA dra, String accountName) throws DraNotFoundException;    

    /**
     * Create a new AdpeAccount object when given the id of a DRA and a name for the account
     *
     * @param draId unique id of the DRA
     * @param accountName   String representing the AdpeAccount name
     * @return  an AdpeAccount object
     * @throws DraNotFoundException  thrown when attempting to create an AdpeAccount with an invalid DRA
     */
    AdpeAccount createAccount(int draId, String accountName) throws DraNotFoundException;

    void assignPrimaryCustodian(Map custodianMap) throws ServiceException;

    /**
     * Assign alternate custodian to account
     *
     * @param adpeAccountId     int representing the unique id of the adpe account
     * @param alternateCustodianUserId  an integer array with the unique user ids of the primary custodians assigned to
     *          the account
     * @throws ServiceException
     * @throws IllegalUnassignmentOfPrimaryCustodianException
     */
    void assignAlternateCustodian(int adpeAccountId, Integer[] alternateCustodianUserId) throws ServiceException, IllegalUnassignmentOfPrimaryCustodianException;

    /**
     * Assign alternate custodian to account
     *
     * @deprecated
     * @param custodianMap
     * @throws ServiceException
     * @throws IllegalUnassignmentOfPrimaryCustodianException
     */
    void assignAlternateCustodian(Map custodianMap) throws ServiceException, IllegalUnassignmentOfPrimaryCustodianException;

    void removeAlternateCustodian(int accountId, int userId) throws AdpeAccountNotFoundException,
            UserNotFoundException;

    void saveOrUpdate(AdpeAccount account);
}
